package com.gitee.helioz.openai.api.endpoint.moderations;

import com.gitee.helioz.openai.api.OpenAiService;
import com.gitee.helioz.openai.api.dto.moderations.ModerationCreateRequest;
import com.gitee.helioz.openai.api.dto.moderations.ModerationCreateResponse;
import com.gitee.helioz.openai.common.constants.OpenAiApiUrl;
import com.gitee.helioz.openai.common.util.json.GsonUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 〈内容过滤服务〉
 *
 * @author <a href="https://gitee.com/helioz">Morning Starr</a>
 */
@Slf4j
@RequiredArgsConstructor
public class ModerationServiceImpl implements ModerationService {

    private final OpenAiService openAiService;

    @Override
    public ModerationCreateResponse create(ModerationCreateRequest createRequest) {
        String requestJson = GsonUtil.toJson(createRequest);
        String responseStr = openAiService.post(OpenAiApiUrl.Moderations.CREATE.getUrl(openAiService.getApiHost()), requestJson);
        return GsonUtil.fromJson(responseStr, ModerationCreateResponse.class);
    }
}
